package goim

type OpType int32

const (
	/* Adopted from goim api/protocol/operation.go */
	// OpSendMsg send message.
	OpSendMsg OpType = 4
	// OpSendMsgReply  send message reply
	OpSendMsgReply OpType = 5
)

const (
	// MaxBodySize max proto body size
	MaxBodySize = int32(1 << 12)
)

const (
	// size
	_packSize      = 4
	_headerSize    = 2
	_verSize       = 2
	_opSize        = 4
	_seqSize       = 4
	_heartSize     = 4
	_rawHeaderSize = _packSize + _headerSize + _verSize + _opSize + _seqSize
	_maxPackSize   = MaxBodySize + int32(_rawHeaderSize)
	// offset
	_packOffset   = 0
	_headerOffset = _packOffset + _packSize
	_verOffset    = _headerOffset + _headerSize
	_opOffset     = _verOffset + _verSize
	_seqOffset    = _opOffset + _opSize
	_heartOffset  = _seqOffset + _seqSize
)

type Proto struct {
	Ver  int32
	Op   OpType
	Seq  int32
	Body []byte
}

func (t OpType) String() string {
	ret := ""
	switch t {
	case OpSendMsg:
		ret = "operation: send message"
	case OpSendMsgReply:
		ret = "operation: send message reply"
	}

	return ret
}
